class EventStore{
    // { name: 'event1', callbackList: [callback1,callback2] }[]
    eventList = [] 
    // 注册事件回调
    on = (eventname, callback) => {
        const findOne = this.eventList.find( item=> item.name ===eventname);
        if(!findOne){
            this.eventList.push({
                name:eventname,
                callbackList: [callback]
            })
        }else{
            findOne.callbackList.push(callback)
        }
    }
    // 触发事件，执行事件对应的回调数组
    emit = (eventname, params) => {
        const findOne = this.eventList.find( item=> item.name ===eventname);
        findOne?.callbackList.forEach(callback => callback(params))

    }
}

export default new EventStore();